//
//  UIManager.m
//  Mecca
//
//  Created by Ryan Enguero on 5/20/14.
//  Copyright (c) 2014 TapDash Heuristics. All rights reserved.
//

#import "UIManager.h"

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "NewsFeedViewController.h"
#import "TopDownloadedViewController.h"
#import "PlayListViewController.h"
#import "EventsViewController.h"
#import "FavoritesViewController.h"

#import "ArtistViewController.h"
#import "AlbumViewController.h"
#import "LiveStreamViewController.h"
#import "SchedulesViewController.h"
#import "PhotosViewController.h"
#import "SongsViewController.h"
#import "PlaySongViewController.h"
#import "PlaySongListViewController.h"
#import "RotationTabViewController.h"
#import "IIViewDeckController.h"
#import "UserProfileViewController.h"
#import "EditProfileViewController.h"
#import "HomePageViewController.h"


#import "FeaturedArtistViewController.h"
#import "FeaturedSongsViewController.h"
#import "NewArtistViewController.h"
#import "NewSongsViewController.h"
#import "AOTMViewController.h"
#import "NewsFeedContentViewController.h"

#import "ScanQRViewController.h"


static UIManager *sharedItem = nil;

@implementation UIManager

- (UINavigationController*)navWithLogin{

    self.loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    
    UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:self.loginView];
    
    return navBar;
}

- (UIViewController*)registerViewController{

    self.registerView = [[RegisterViewController alloc] initWithNibName:@"RegisterViewController" bundle:nil];
    
    return self.registerView;
}

- (UIViewController *)albumViewController{

    self.albumView = [[AlbumViewController alloc] initWithNibName:@"AlbumViewController" bundle:nil];
    
    return self.albumView;

}

- (UIViewController *)playSongListViewController{
    
    self.playSongListView = [[PlaySongListViewController alloc] initWithNibName:@"PlaySongListViewController" bundle:nil];

    return self.playSongListView;

}


- (UIViewController *)editProfileViewController{
    
    self.editProfileView = [[EditProfileViewController alloc] initWithNibName:@"EditProfileViewController" bundle:nil];
    
    return self.editProfileView;
    
}


- (IIViewDeckController*)generateControllerStack{
    
    self.userProfileView = [[UserProfileViewController alloc] initWithNibName:@"UserProfileViewController" bundle:nil];
    
    
    
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    
    self.artistView = [[ArtistViewController alloc] initWithNibName:@"ArtistViewController" bundle:nil];
    self.newsFeedView = [[NewsFeedViewController alloc] initWithNibName:@"NewsFeedViewController" bundle:nil];
    self.topDownloadedView = [[TopDownloadedViewController alloc] initWithNibName:@"TopDownloadedViewController" bundle:nil];
    self.homePageView = [[HomePageViewController alloc] initWithNibName:@"HomePageViewController" bundle:nil];
    
    
        tabBar.viewControllers = @[self.newsFeedView, self.artistView, self.topDownloadedView];
        tabBar.selectedViewController = self.newsFeedView;
    
    UINavigationController *navHome = [[UINavigationController alloc] initWithRootViewController:self.homePageView];
    
    self.rotationView = [[RotationTabViewController alloc] initWithNibName:@"RotationTabViewController" bundle:nil];
    
    self.rotationView.viewControllers = @[@"HomeView",@"NewsFeedView", @"ArtistView", @"TopDownloadedView", @"PlayListView", @"EventsView", @"FavoritesView"];
    
    self.viewDeck =  [[IIViewDeckController alloc] initWithCenterViewController:navHome
                                                                   leftViewController:self.rotationView
                                                                  rightViewController:self.userProfileView];
    self.viewDeck.leftSize = 50;
    
    [self.viewDeck disablePanOverViewsOfClass:NSClassFromString(@"_UITableViewHeaderFooterContentView")];
    
    return self.viewDeck;
    
}

- (UIViewController*)songsViewController{

    self.songsView = [[SongsViewController alloc] initWithNibName:@"SongsViewController" bundle:nil];
    
    return self.songsView;
}

- (UIViewController*)playSong{
    
    self.playSongView = [[PlaySongViewController alloc] initWithNibName:@"PlaySongViewController" bundle:nil];
    
        
    return self.playSongView;
}

-(UIViewController *)newsFeedViewController{
    
    self.newsFeedView = [[NewsFeedViewController alloc] initWithNibName:@"NewsFeedViewController" bundle:nil];
    
//    UINavigationController *navBarNews = [[UINavigationController alloc] initWithRootViewController:self.newsFeedView];
//    
//    [navBarNews.navigationBar setBackgroundImage:[UIImage imageNamed:@"navNewsFeedImg.png"] forBarMetrics:UIBarMetricsDefault];
    
    
    return self.newsFeedView;

}

-(UIViewController*)homePageViewController{
    
    self.homePageView = [[HomePageViewController alloc] initWithNibName:@"HomePageViewController" bundle:nil];
    
    return self.homePageView;
    
}

- (UIViewController*)loginViewController{
    
    self.loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    
    return self.loginView;
}




- (UIViewController*)featuredArtistViewController{
    self.featuredArtistView = [[FeaturedArtistViewController alloc] initWithNibName:@"FeaturedArtistViewController" bundle:nil];
    
    return self.featuredArtistView;
}

- (UIViewController*)featuredSongsViewController{
    
    self.featuredSongsView = [[FeaturedSongsViewController alloc] initWithNibName:@"FeaturedSongsViewController" bundle:nil];
    
    return self.featuredSongsView;
    
}




- (UIViewController*)newArtistViewController{
    
    self.nArtistView = [[NewArtistViewController alloc] initWithNibName:@"NewArtistViewController" bundle:nil];
    
    return self.nArtistView;
    
}

- (UIViewController*)newSongsViewController{
    
    self.nSongsView = [[NewSongsViewController alloc] initWithNibName:@"NewSongsViewController" bundle:nil];
    
    return self.nSongsView;
    
}


- (UIViewController*)artistOfTheMonthViewController{
    
    self.artistOfTheMonthView = [[AOTMViewController alloc] initWithNibName:@"AOTMViewController" bundle:nil];
    
    return self.artistOfTheMonthView;
}


- (UIViewController *)artistViewController{

    self.artistView = [[ArtistViewController alloc] initWithNibName:@"ArtistViewController" bundle:nil];
    
//    UINavigationController *navBarArtist = [[UINavigationController alloc] initWithRootViewController:self.artistView];
//
//    [navBarArtist.navigationBar setBackgroundImage:[UIImage imageNamed:@"artistTabImg.png"] forBarMetrics:UIBarMetricsDefault];
    
    return self.artistView;

}

- (UIViewController*)topDownloadedViewController{

    self.topDownloadedView = [[TopDownloadedViewController alloc] initWithNibName:@"TopDownloadedViewController" bundle:nil];
    
 //   UINavigationController *navBarTopDL = [[UINavigationController alloc] initWithRootViewController:self.topDownloadedView];
    
    return self.topDownloadedView;

}

- (UINavigationController*)playListViewController{

    self.playListView = [[PlayListViewController alloc] initWithNibName:@"PlayListViewController" bundle:nil];
    
    UINavigationController *navBarPlayList = [[UINavigationController alloc] initWithRootViewController:self.playListView];
    
    return navBarPlayList;

}

- (UIViewController*)eventsViewController{

    self.eventsView = [[EventsViewController alloc] initWithNibName:@"EventsViewController" bundle:nil];
    
  //  UINavigationController *navBarEvents = [[UINavigationController alloc] initWithRootViewController:self.eventsView];
    
    return self.eventsView;

}

- (UIViewController*)favoritesViewController{

    self.favoritesView = [[FavoritesViewController alloc] initWithNibName:@"FavoritesViewController" bundle:nil];
    
  //  UINavigationController *navBarFavorites = [[UINavigationController alloc] initWithRootViewController:self.favoritesView];
    
    return self.favoritesView;

}


- (UIViewController*)scanViewController{

    self.scanView = [[ScanQRViewController alloc] initWithNibName:@"ScanQRViewController" bundle:nil];
    
    return self.scanView;

}



- (UITabBarController*)artistTabBars{


    self.albumView = [[AlbumViewController alloc] initWithNibName:@"AlbumViewController" bundle:nil];

    self.liveStreamView = [[LiveStreamViewController alloc] initWithNibName:@"LiveStreamViewController" bundle:nil];
    self.schedulesView = [[SchedulesViewController alloc] initWithNibName:@"SchedulesViewController" bundle:nil];
    self.photosView = [[PhotosViewController alloc] initWithNibName:@"PhotosViewController" bundle:nil];

    
    UINavigationController *albumNav = [[UINavigationController alloc] initWithRootViewController:self.albumView];
    
    UINavigationController *liveStreamNav = [[UINavigationController alloc] initWithRootViewController:self.liveStreamView];
    
    UINavigationController *schedulesNav = [[UINavigationController alloc] initWithRootViewController:self.schedulesView];
    
    UINavigationController *photosNav = [[UINavigationController alloc] initWithRootViewController:self.photosView];
    
//    [albumNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"albumNavImg.png"] forBarMetrics:UIBarMetricsDefault];
//    [liveStreamNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"liveStreamNav.png"] forBarMetrics:UIBarMetricsDefault];
//    [schedulesNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"schedulesNav.png"] forBarMetrics:UIBarMetricsDefault];
//    [photosNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"photosNav.png"] forBarMetrics:UIBarMetricsDefault];
    
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    
    tabBar.viewControllers = @[albumNav, liveStreamNav, schedulesNav, photosNav];
    tabBar.selectedViewController = albumNav;
    [tabBar.tabBar setBackgroundImage:[UIImage imageNamed:@"tabArtistBg.png"]];
    
    return tabBar;
}



- (UIViewController*)newsFeedContentViewController{
    
    self.newsFeedContentView = [[NewsFeedContentViewController alloc] initWithNibName:@"NewsFeedContentViewController" bundle:nil];
    
    //  UINavigationController *navBarFavorites = [[UINavigationController alloc] initWithRootViewController:self.favoritesView];
    
    return self.newsFeedContentView;
}



- (void)openLeft{
    
    [self.viewDeck toggleLeftView];
    
    //[self.viewDeck openLeftViewAnimated:YES];
}




-(void)closeLeft{
    
    [self.viewDeck closeLeftViewAnimated:YES];
}


- (void)openRight{
    
    [self.viewDeck openRightViewAnimated:YES];
    
    
}

- (void)logOut{
    
    [self.viewDeck.navigationController popViewControllerAnimated:YES];
    //dismissViewControllerAnimated:YES completion:nil];
    
}

#pragma mark - SingleTon

+ (UIManager *)sharedItems
{
    if (sharedItem == nil) {
        sharedItem = [[super allocWithZone:NULL]init];
    }
    return  sharedItem;
}
- (id)init{
    if ((self = [super init])) {
        
    }
    return self;
}
+ (id)allocWithZone:(NSZone *)zone{
    return  [self sharedItems];
}
- (id)copyWithZone:(NSZone *)zone{
    return self;
}

@end
